import java.util.Scanner;

public class LoanCalculator {

    private double a; //贷款额度（万元）
    private int m; //还款时间（月）
    private double i; //月利率

    public LoanCalculator(double amount,int month,double annualRate){
        this.a = amount;
        this.m = month;
        this.i = annualRate / 12;
    }
    public void input(){
        Scanner In = new Scanner(System.in);
        System.out.println("请输入贷款总额（万元）:");
        a = In.nextDouble();
        System.out.println("请输入贷款时间（月）:");
        m = In.nextInt();
        System.out.println("请输入年利率:");
        double annualRate = In.nextDouble();
        i = annualRate / 12;
    }

    public double calculateEqualPrincipalInterest(){
        return (m + 1) * a * i / 2;
    }

    public double calculateEqualInstallmentInterest(){
        double totalInterest = m * a * i * Math.pow((1 + i), m) / (Math.pow((1 + i), m) - 1) - a;
        return totalInterest;
    }

    public void displayResults(){
        double principalInterest = calculateEqualPrincipalInterest();
        double installmentInterest = calculateEqualInstallmentInterest();
        System.out.println("等额本金还款法总利息为:" + principalInterest + "万元");
        System.out.println("等额本息还款法总利息为:" + installmentInterest + "万元");
    }
}
